/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ufrgs.inf.delphos.extraction.model.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENamedElementImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import ufrgs.inf.delphos.extraction.model.DCompilationUnit;
import ufrgs.inf.delphos.extraction.model.DPackage;
import ufrgs.inf.delphos.extraction.model.DelphosSystemModelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DPackage</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DPackageImpl#getCompUnitsList <em>Comp Units</em>}</li>
 *   <li>{@link ufrgs.inf.delphos.extraction.model.impl.DPackageImpl#getPackagesList <em>Packages</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DPackageImpl extends ENamedElementImpl implements DPackage {
	/**
	 * The cached value of the '{@link #getCompUnitsList() <em>Comp Units</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCompUnitsList()
	 * @generated
	 * @ordered
	 */
	protected EList<DCompilationUnit> compUnits;

	/**
	 * The empty value for the '{@link #getCompUnits() <em>Comp Units</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCompUnits()
	 * @generated
	 * @ordered
	 */
	protected static final DCompilationUnit[] COMP_UNITS_EEMPTY_ARRAY = new DCompilationUnit [0];

	/**
	 * The cached value of the '{@link #getPackagesList() <em>Packages</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPackagesList()
	 * @generated
	 * @ordered
	 */
	protected EList<DPackage> packages;

	/**
	 * The empty value for the '{@link #getPackages() <em>Packages</em>}' array accessor.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPackages()
	 * @generated
	 * @ordered
	 */
	protected static final DPackage[] PACKAGES_EEMPTY_ARRAY = new DPackage [0];

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DPackageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DelphosSystemModelPackage.Literals.DPACKAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DCompilationUnit[] getCompUnits() {
		if (compUnits == null || compUnits.isEmpty()) return COMP_UNITS_EEMPTY_ARRAY;
		BasicEList<DCompilationUnit> list = (BasicEList<DCompilationUnit>)compUnits;
		list.shrink();
		return (DCompilationUnit[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DCompilationUnit getCompUnits(int index) {
		return getCompUnitsList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getCompUnitsLength() {
		return compUnits == null ? 0 : compUnits.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCompUnits(DCompilationUnit[] newCompUnits) {
		((BasicEList<DCompilationUnit>)getCompUnitsList()).setData(newCompUnits.length, newCompUnits);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCompUnits(int index, DCompilationUnit element) {
		getCompUnitsList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DCompilationUnit> getCompUnitsList() {
		if (compUnits == null) {
			compUnits = new EObjectContainmentEList<DCompilationUnit>(DCompilationUnit.class, this, DelphosSystemModelPackage.DPACKAGE__COMP_UNITS);
		}
		return compUnits;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPackage[] getPackages() {
		if (packages == null || packages.isEmpty()) return PACKAGES_EEMPTY_ARRAY;
		BasicEList<DPackage> list = (BasicEList<DPackage>)packages;
		list.shrink();
		return (DPackage[])list.data();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public DPackage getPackages(int index) {
		return getPackagesList().get(index);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPackagesLength() {
		return packages == null ? 0 : packages.size();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPackages(DPackage[] newPackages) {
		((BasicEList<DPackage>)getPackagesList()).setData(newPackages.length, newPackages);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPackages(int index, DPackage element) {
		getPackagesList().set(index, element);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DPackage> getPackagesList() {
		if (packages == null) {
			packages = new EObjectContainmentEList<DPackage>(DPackage.class, this, DelphosSystemModelPackage.DPACKAGE__PACKAGES);
		}
		return packages;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DelphosSystemModelPackage.DPACKAGE__COMP_UNITS:
				return ((InternalEList<?>)getCompUnitsList()).basicRemove(otherEnd, msgs);
			case DelphosSystemModelPackage.DPACKAGE__PACKAGES:
				return ((InternalEList<?>)getPackagesList()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DelphosSystemModelPackage.DPACKAGE__COMP_UNITS:
				return getCompUnitsList();
			case DelphosSystemModelPackage.DPACKAGE__PACKAGES:
				return getPackagesList();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DelphosSystemModelPackage.DPACKAGE__COMP_UNITS:
				getCompUnitsList().clear();
				getCompUnitsList().addAll((Collection<? extends DCompilationUnit>)newValue);
				return;
			case DelphosSystemModelPackage.DPACKAGE__PACKAGES:
				getPackagesList().clear();
				getPackagesList().addAll((Collection<? extends DPackage>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DPACKAGE__COMP_UNITS:
				getCompUnitsList().clear();
				return;
			case DelphosSystemModelPackage.DPACKAGE__PACKAGES:
				getPackagesList().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DelphosSystemModelPackage.DPACKAGE__COMP_UNITS:
				return compUnits != null && !compUnits.isEmpty();
			case DelphosSystemModelPackage.DPACKAGE__PACKAGES:
				return packages != null && !packages.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //DPackageImpl
